package comWorld.blog.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import comWorld.blogCatalog.BlogCatalogs;
import comWorld.user.UserInfo;

/**
 * Servlet implementation class NewBlogPageInit
 */
@WebServlet("/admin/new-blog")
public class NewBlogPageInit extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public NewBlogPageInit() {
        super();
    }

	/**
	 * @see HttpServlet#service(HttpServletRequest request, HttpServletResponse response)
	 */
	public void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		HttpSession session = request.getSession();
		UserInfo user = (UserInfo) session.getAttribute("visitorInfo");
		BlogCatalogs catalogs = (BlogCatalogs) session.getAttribute("blogCatalogs");
		if (catalogs == null || catalogs.getUserId() != user.getId()) {
			catalogs = new BlogCatalogs(user.getId());
			session.setAttribute("blogCatalogs", catalogs);
		}
		
		request.getRequestDispatcher("/blog/newBlog.jsp").forward(request, response);
	}

}
